<div id="page_content">
    <h2><?= $this->t->_('Polls'); ?></h2>
    <form id="<?php echo $this->form->getId(); ?>" action="<?php echo $this->form->getAction(); ?>" method="<?php echo $this->form->getMethod(); ?>">
        <dl class="zend_form">
            <?= $this->form->main ?>
            <fieldset id="fieldset-answers"><legend><?= $this->t->_('Answers'); ?></legend>
                <ul id="sortable">
                    <?php foreach ($this->answers as $v): ?>
                        <li>
                        <dt id="answer-label"><label for="answer-<?= $v->id ?>" class="answer_label"></label></dt>
                        <dd id="answer-element">
                            <input type="text" class="width_2_3" name="answer[<?= $v->id ?>]" id="answer-<?= $v->id ?>" value="<?= $v->answer ?>" />
                            <input type="text" class="width_1_3" name="votes[<?= $v->id ?>]" id="result-<?= $v->id ?>" value="<?= $v->votes ?>" />
                            <a class="draggable_field"><span><?= $this->t->_('Remove') ?></span></a>
                        </dd>
                        <div class="clear"></div>
                        </li>
                    <?php endforeach; ?>
                    </ul>
                </fieldset>
            <?= $this->form->settings ?>
                    </dl>
                </form>
            </div>
            <div id="sidebar">
                <a href="<?= ADMIN_URL . '/pages/modify/id/' . $this->section->id . '/a/new' ?>" class="sidebar_button add_button"><?= $this->t->_("New poll") ?></a>
            </div>

            <script type="text/javascript">
                function updateButtons(){
                    $('.answer_label').html('<a class="remove_field"><span><?= $this->t->_('Remove') ?></span></a>');
                    $('#answer-label').children().html(
                        '<a class="remove_field"><span><?= $this->t->_('Remove') ?></span></a>' +
                        '<a class="add_field"><span><?= $this->t->_('Add') ?></span></a>'
                    );
                }
                
                $("#sortable").sortable({
                   stop: function(event, ui) { updateButtons(); }
                });

                updateButtons();

                $('.add_field').live('click', function() {
                    element = '<li><dt id="answer-label"><label for="answer>" class="answer_label"></label></dt><dd id="answer-element"><input type="text" class="width_2_3" name="answer[]" id="answer" value="" /><input type="text" class="width_1_3" name="votes[]" id="result" value="" /><a class="draggable_field"><span></span></a></dd><div class="clear"></div></li>';
                    $('fieldset#fieldset-answers ul').append(element);
                    updateButtons();
                });
                
                $('.remove_field').live('click', function() {
                    $(this).parent().parent().parent().remove();
                    updateButtons();
                });
                
</script>